package com.ihisun.tmhcms.controller.sysusercontroller;

import com.ihisun.tmhcms.core.dao.sysroledao.EditSysRoleDao;
import com.ihisun.tmhcms.core.dto.sysroledto.SysRoleDto;
import com.ihisun.tmhcms.core.dto.sysuserdto.EditUserPwdDto;
import com.ihisun.tmhcms.core.dto.sysuserdto.SysUserDto;
import com.ihisun.tmhcms.core.service.sysuserservice.SysUserService;
import com.ihisun.tmhcms.core.vo.SysUserVo;
import com.ihisun.tmhcms.utils.ResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;



import javax.annotation.Resource;


@Api(tags = "系统用户相关Api")
@RestController
@RequestMapping("user")
public class SysUserController {

    @Resource
    SysUserService sysUserService;
    @Resource
    EditSysRoleDao editSysRoleDao;


    /**
     * 逻辑security拦截处理
     * @param username
     * @param password
     */
    @PostMapping("/login")
    @ApiOperation("登录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",value = "账户",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "password",value = "密码",dataType = "String",paramType = "query")
    })
    public void login(String username,String password){

    }

    /**
     * 逻辑security拦截处理
     */
    @GetMapping("/loginOut")
    @ApiOperation("退出")
    public void loginOut(){

    }

    @GetMapping("/findByJurisdiction")
    @ApiOperation(value = "权限列表")
    public ResponseVo findByJurisdiction(){
        return sysUserService.jurisdiction();
    }


    @GetMapping("/findByRole")
    @ApiOperation("角色列表")
    public ResponseVo findByRole(){
        return sysUserService.findByRole();
    }

    @PostMapping("/editRole")
    @ApiOperation("编辑角色")
    public ResponseVo editRole(@RequestBody SysRoleDto sysRoleDto){
       return sysUserService.editRole(sysRoleDto);
    }

    @GetMapping("/deleteRole")
    @ApiOperation("删除角色")
    public ResponseVo deleteRole(String id){
        int i = editSysRoleDao.deleteByRoleId(Long.parseLong(id));
        if (i>0){
            return ResponseVo.ok();
        }
        return ResponseVo.error();
    }

    @PostMapping("/editUser")
    @ApiOperation(value = "编辑角色")
    public ResponseVo editUser(@RequestBody SysUserDto sysUserDto){

        return  sysUserService.editUser(sysUserDto);
    }

    @GetMapping("/updateUserState")
    @ApiOperation("修改用户状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "角色Id",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "state",value = "角色状态    状态:1正常  2禁用  3删除",dataType = "String",paramType = "query")
    }
    )
    public ResponseVo updateUserState(String id,String state){

        return sysUserService.updateUserState(id,state);
    }
@GetMapping("userList")
@ApiOperation(value = "系统用户集合",response = SysUserVo.class)
public ResponseVo userList(){
   return sysUserService.sysUserList();
}

     @PostMapping("/updatePassword")
     @ApiOperation("/修改用户密码")
     public  ResponseVo updatePassword(@RequestBody EditUserPwdDto editUserPwdDto){
        return sysUserService.updatePassword(editUserPwdDto);
     }
}
